package com.xuecheng.search.controller;

import com.xuecheng.api.search.EsCourseControllerApi;
import com.xuecheng.framework.domain.search.CourseBaseSearch;
import com.xuecheng.framework.domain.search.CourseSearchParam;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.search.service.EsCourseService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@RestController
@RequestMapping("/course/search")
public class EsCourseController implements EsCourseControllerApi {
    @Resource
      private   EsCourseService esCourseService;


    /**
     * 分页搜索数据
     *
     * @param page 页码
     * @param size 每页显示多少个
     * @return 结果
     * @pram courseSearchParam 搜索参数
     */
    @Override
    @GetMapping("/list/{page}/{size}")
    public QueryResponseResult<CourseBaseSearch> list(@PathVariable("page") int page, @PathVariable("size") int size, CourseSearchParam courseSearchParam) {
        return esCourseService.list(page, size, courseSearchParam);
    }

    /**
     * 根据课程id查询一个数据
     *
     * @param courseId 课程id
     * @return 查询的结果
     */
    @Override
    @GetMapping("/{courseId}")
    public QueryResponseResult<CourseBaseSearch> findByCourseId(@PathVariable String courseId) {
        return esCourseService.findByCourseId(courseId);
    }
}
